package com.hema.auction.widget.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hema.auction.R;
import com.hema.auction.activity.H5Activity;
import com.hema.auction.utils.Constant;
import com.hema.auction.utils.GlideUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 描述:个人中心item
 * 作者:john
 */
public class CenterItemView extends LinearLayout {
    @BindView(R.id.iv_icon)
    ImageView ivIcon;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.ll_item)
    LinearLayout llItem;

    public CenterItemView(Context context) {
        super(context);
        init();
    }

    public CenterItemView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CenterItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        ButterKnife.bind(this, LayoutInflater.from(getContext()).inflate(R.layout.layout_center_item, this));
    }

    public void setData(String iconUrl, String name,String url) {
        GlideUtils.load(getContext(),iconUrl,ivIcon);
        tvName.setText(name);
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString(Constant.EXTRA_TITLE, name);
                bundle.putString(Constant.EXTRA_URL, url);
                Intent intent = new Intent(getContext(), H5Activity.class);
                intent.putExtras(bundle);
                getContext().startActivity(intent);
            }
        });
    }
}
